package com.huajin.codetest.pdf;

import java.time.LocalDateTime;
import java.util.Objects;

import com.huajin.codetest.domain.pdf.AddSealText;
import com.huajin.codetest.enums.SealEnum;
import com.huajin.codetest.util.Constants;
import com.huajin.codetest.util.DateTimeUtil;
import com.huajin.codetest.util.PdfUtil;

public class PdfTest {

    public static void addSealText(String receiptPledgeFilePath, SealEnum sealEnum, AddSealText addSealText) {
        String companyName = addSealText.getCompanyName();
        String pledgeCompanyName = addSealText.getPledgeCompanyName();
        String localDate =   DateTimeUtil.localDateToDateString(addSealText.getTime().toLocalDate(), Constants.DATE_TIME_CN_FORMAT);
        String text = "";
        boolean breakFlag = false;
        float x = 0F;
        float y = 0F;
        if (Objects.equals(SealEnum.仓单_融资企业确认质押, sealEnum)) {
            String line = "背书内容：该电子仓单已质押给" + pledgeCompanyName  + PdfUtil.BREAK_FLAG;
            if (line.length() > PdfUtil.BREAK_LINE) {
                line = line.substring(0, PdfUtil.BREAK_LINE) + PdfUtil.BREAK_FLAG + line.substring(PdfUtil.BREAK_LINE);
                breakFlag = true;
            }
            text= "背书事项：质押业务" + PdfUtil.BREAK_FLAG +
                    line +
                    "背书人："+ companyName + PdfUtil.BREAK_FLAG +
                    (breakFlag ? PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG  : PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG) +
                    "                                          （背书人签章）" + PdfUtil.BREAK_FLAG +
                    "                                          日期：" + localDate;
            x = 58F;
            y = 120F;
        } else if (Objects.equals(SealEnum.仓单_仓储企业确认质押, sealEnum)) {
            String line = "保管人声明：该电子仓单已由"  + addSealText.getGoodsCompanyName() + "质押给" + pledgeCompanyName  + PdfUtil.BREAK_FLAG;
            if (line.length() > PdfUtil.BREAK_LINE) {
                line = line.substring(0, PdfUtil.BREAK_LINE) + PdfUtil.BREAK_FLAG + line.substring(PdfUtil.BREAK_LINE);
                breakFlag = true;
            }
            text= "背书事项：质押业务" + PdfUtil.BREAK_FLAG +
                    line +
                    "保管人："+ companyName + PdfUtil.BREAK_FLAG +
                    (breakFlag ? PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG  : PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG) +
                    "                                          （保管人签章）" + PdfUtil.BREAK_FLAG +
                    "                                          日期：" + localDate;
            x = 305F;
            y = 120F;
        } else if (Objects.equals(SealEnum.仓单_资金方确认解质押, sealEnum)) {
            text= "背书事项：解质押业务" + PdfUtil.BREAK_FLAG +
                    "背书内容：该电子仓单已解除质押" + PdfUtil.BREAK_FLAG +
                    "背书人："+ companyName  + PdfUtil.BREAK_FLAG +
                    PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG +
                    "                                          （背书人签章）" + PdfUtil.BREAK_FLAG +
                    "                                          日期：" + localDate;
            x = 58F;
            y = 295F;
        } else if (Objects.equals(SealEnum.仓单_仓储企业确认注销, sealEnum)) {
            text= "背书事项：注销" + PdfUtil.BREAK_FLAG +
                    "保管人声明：该电子仓单已注销" + PdfUtil.BREAK_FLAG +
                    "保管人："+ companyName + PdfUtil.BREAK_FLAG +
                    PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG + PdfUtil.BREAK_FLAG +
                    "                                          （保管人签章）" + PdfUtil.BREAK_FLAG +
                    "                                          日期：" + localDate;
            x = 305F;
            y = 295F;
        }
        PdfUtil.addText(receiptPledgeFilePath, text, x, y);
    }

    public static void main(String[] args) {
        AddSealText addSealText = new AddSealText();
        addSealText.setCompanyName("中仓登信息有限公司");
        addSealText.setTime(LocalDateTime.now());
        String basePath = "";
        String fileName = "";
        addSealText(basePath + fileName, SealEnum.仓单_仓储企业确认注销, addSealText);

    }

}
